package wodegua.d13_time;

import java.time.*;
import java.time.format.DateTimeFormatter;

public class Test {
    public static void main(String[] args) {
        // 本地日期，年、月、日
        LocalDate ld = LocalDate.now();
        LocalDateTime ldt = LocalDateTime.now();
        System.out.println("今天是"+ld);
        System.out.println("今年是"+ld.getYear());
        System.out.println("本月是"+ld.getMonthValue());
        System.out.println("今天是这个月的"+ld.getDayOfMonth());
        System.out.println("今天是"+ld.getDayOfWeek().getValue());
        System.out.println("今天是"+ld.getDayOfWeek().name());
        // 本地时间，时、分、秒、纳秒
        // 本地日期、时间，年、月、日、时、分、秒、纳秒

        System.out.println("-----------------------------------------------");

        ZoneId zoneId = ZoneId.systemDefault();
        System.out.println(zoneId.getId());

        System.out.println(ZoneId.getAvailableZoneIds());
        System.out.println("-----------------------------------------------");


        Instant instant = Instant.now();
        System.out.println(instant.getEpochSecond());
        System.out.println(instant.getNano());


        LocalDateTime now = LocalDateTime.now();
        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy年MM月dd日 HH时mm分ss秒");
        System.out.println(formatter.format(now));

        String str = "2024年03月07日 11时29分04秒";
        System.out.println(LocalDateTime.parse(str, formatter));
        System.out.println("-----------------------------------------------");

        LocalDate start = LocalDate.of(2023, 10, 31);
        LocalDate end = LocalDate.of(2024, 10, 10);
        Period period = Period.between(start,end);
        System.out.println(period.getYears());
        System.out.println(period.getMonths());
        System.out.println(period.getDays());

        LocalDate startPlus = start.plusDays(1);
        System.out.println("加一天后月份："+startPlus.getMonthValue());
        System.out.println("-----------------------------------------------");

        LocalDateTime startTIme = LocalDateTime.of(2023, 11, 10, 10, 0, 0);
        LocalDateTime endTIme = LocalDateTime.of(2023, 11, 10, 0, 0, 0);
        Duration duration = Duration.between(startTIme, endTIme);
        System.out.println(duration.toDays());
        System.out.println(duration.toHours());
        System.out.println(duration.toMinutes());
        System.out.println(duration.toMillis());
    }
}
